import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import wsClient from './utils/socket'

const app = createApp(App)
app.use(store)
app.use(router)
app.use(ElementPlus)

// 修改WebSocket连接初始化方式
// 仅在特定路由下才进行WebSocket连接，避免影响登录/注册页面
router.afterEach((to) => {
  if (to.meta.requiresAuth && localStorage.getItem('token')) {
    // 只有登录后的需要认证的页面才尝试连接WebSocket
    try {
      wsClient.connect()
    } catch (error) {
      console.warn('WebSocket连接失败，但不影响基本功能', error)
    }
  }
})

app.mount('#app') 